package com.zcx.qshop.adapter;

import android.app.Activity;
import android.content.Context;
import android.net.Uri;
import android.text.Html;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.facebook.drawee.view.SimpleDraweeView;
import com.zcx.helper.bound.BoundView;
import com.zcx.helper.bound.BoundViewHelper;
import com.zcx.qshop.QSApplication;
import com.zcx.qshop.R;
import com.zcx.qshop.entity.Good;

import java.util.List;

/**
 * Created by Administrator on 2015/8/22 0022.
 */
public class HistoryAdapter extends QSAdapter<Good> {

    private LayoutInflater layoutInflater;

    public HistoryAdapter(Context context, List<Good> objects) {

        super(context, objects);

        layoutInflater = ((Activity)context).getLayoutInflater();

    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {

        Good good = getItem(position);

        ViewHolder viewHolder;

        if(convertView == null){

            convertView = BoundViewHelper.boundView(viewHolder = new ViewHolder(), QSApplication.ScaleScreenHelper.loadView((ViewGroup) layoutInflater.inflate(R.layout.item_history, null)));

            convertView.setTag(viewHolder);

        }else{

            viewHolder = (ViewHolder) convertView.getTag();

        }

        viewHolder.img.setImageURI(Uri.parse(good.picurl));

        viewHolder.name.setText(Html.fromHtml(good.title)) ;

        viewHolder.price.setText("￥" + good.price);

        viewHolder.unit.setText("元/" + good.unit);

        return convertView;

    }

    private class ViewHolder{

        @BoundView(R.id.item_hisory_img) public SimpleDraweeView img;

        @BoundView(R.id.item_hisory_name) public TextView name;

        @BoundView(R.id.item_hisory_price) public TextView price;

        @BoundView(R.id.item_hisory_unit) public TextView unit;

    }

}
